create or replace view v_res_organ_r_ppt as
select t1.t_res_organ_r_ppt_id,
       t1.t_res_organ_id,
       t2.name                   as Organ_Name,
       t1.t_res_organ_ext_ppt_id,
       t3.name                   as PPT_NAME,
       t3.data_type,
       t3.precision,
       t1.value,
       t4.name as ValueName
  from T_RES_ORGAN_R_PPT t1, t_Res_Organ t2, T_RES_ORGAN_EXT_PPT t3, t_Res_Value_Object t4
 where t1.t_res_organ_id = t2.t_res_organ_id
   and t1.t_res_organ_ext_ppt_id = t3.t_res_organ_ext_ppt_id
   and t1.value = t4.t_res_value_object_id(+)
   and t3.data_type = 'ValueObject'
union all
select t1.t_res_organ_r_ppt_id,
       t1.t_res_organ_id,
       t2.name                   as Organ_Name,
       t1.t_res_organ_ext_ppt_id,
       t3.name                   as PPT_NAME,
       t3.data_type,
       t3.precision,
       t1.value,
       '' as ValueName
  from T_RES_ORGAN_R_PPT t1, t_Res_Organ t2, T_RES_ORGAN_EXT_PPT t3
 where t1.t_res_organ_id = t2.t_res_organ_id
   and t1.t_res_organ_ext_ppt_id = t3.t_res_organ_ext_ppt_id
   and t3.data_type != 'ValueObject';
